<?php

namespace app\h5\Controller;

use think\Db;
use think\Request;
use think\Controller;

class Suggest extends Controller
{

    public function Index()
    {
        return $this->fetch('index');
    }

    public function add()
    {
        $request = Request::instance();
        //提交操作
        $post = $request->param();
        $validate = new \think\Validate([
            ['username', 'require', '姓名不能为空'],
            ['mobile', 'require', '联系方式不能为空'],
            ['content', 'require', '建议不能为空'],
        ]);
        //验证部分数据合法性
        if (!$validate->check($post)) {
            return $this->error('提交失败：' . $validate->getError());
        }

        if(!preg_match('/^[\x7f-\xff]+$/', $post['username'])){
            return $this->error('提交失败：' . '请输入正确姓名');
        }
        if(!preg_match('/^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|(19[0-9])|166|198|199)\d{8}$/', $post['mobile'])){
            return $this->error('提交失败：' . '请输入正确手机号');
        }
        



        $post['addtime'] = time();
        $post['staue'] = '10';
        $post['is_delete'] = '0';
        $res = Db::name('suggest')->insert($post);
        if($res){
            return $this->success('提交成功，感谢您的建议！','h5/suggest/index');
        }else{
            return $this->error('提交失败：' . $validate->getError());
        }


    }


}
